package com.dongdongshop.controller;

import com.dongdongshop.domain.AjaxResult;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.ContentCatService;
import em.ResuleEnum;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("contentCat")
public class contentCatController {

    @DubboReference
    private ContentCatService contentCatService;


    @RequestMapping("contentCategoryShow")
    public String contentCategoryShow(){
        return "admin/content_category";
    }

    @RequestMapping("contentCatList")
    @ResponseBody
    public AjaxResult contentCatList(String name){
        List<TbContentCategory> list = contentCatService.selectInfo(name);
        return AjaxResult.R(ResuleEnum.SUCCESS).setData(list);
    }

    @RequestMapping("insertList")
    @ResponseBody
    public AjaxResult insertList(TbContentCategory tbContentCategory){
        contentCatService.insertList(tbContentCategory);
        return AjaxResult.ok();
    }

    @RequestMapping("selectBycontentCatById")
    @ResponseBody
    public AjaxResult selectBycontentCatById(Long id){
        TbContentCategory tbContentCategory = contentCatService.selectBycontentCatById(id);
        return AjaxResult.R(ResuleEnum.SUCCESS).setData(tbContentCategory);
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public AjaxResult updateInfo(TbContentCategory tbContentCategory){
        contentCatService.updateInfo(tbContentCategory);
        return AjaxResult.R(ResuleEnum.SUCCESS);
    }

    @RequestMapping("deleteInfo")
    @ResponseBody
    public AjaxResult deleteInfo(@RequestParam("ids[]")Long[] ids){
        contentCatService.deleteInfo(ids);
        return AjaxResult.ok();
    }
}
